// pages/exam1/result/result.js
Page({
  data: {
    answerStatus: [
      { status: 'wrong-bck' },
      { status: 'unanswer-bck' },
      { status: 'wrong-bck' },
      { status: 'correct-bck' },
      { status: 'wrong-bck' },
      { status: 'correct-bck' },
      { status: 'correct-bck' },
      { status: 'unanswer-bck' },
      { status: 'wrong-bck' },
    ]
  },
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    let that = this
    eventChannel.on('examList', function (data) {
      // 统计对错
      let correct = 0;
      let wrong = 0;
      for (const exam of data.examList) {
        if (exam.selected.length === 0) {
          wrong++;
        } else if (exam.selected.join(',') === exam.answer_tags) {
          correct++;
        } else {
          wrong++;
        }
      }
      that.setData({
        examList: data.examList,
        rate: parseInt(correct / data.examList.length * 100),
        correct: correct,
        wrong: wrong
      });
      console.log('examList', data)
      that.canvasRing = that.selectComponent('#canringA');
      that.canvasRing.drawCanvasRing(); // 绘制圆环A
    });
  },
  selectAnswer(e) {
    // const index = e.currentTarget.dataset.index;
    // wx.showToast({
    //   title: `选择第${index + 1}题`,
    //   icon: 'none'
    // });
  }
});
